﻿// DATE     : 16-05-2012
// AUTHOR   : jsimoes
// PROJECT  : Zon.Core.Vimeo.FE
// FILENAME : FunctionBase.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MarsExplorerWebSite.Interfaces;

namespace MarsExplorerWebSite.Functions
{
    /// <summary>
    /// this is the abstract class of all the functions provided
    /// </summary>
    public abstract class FunctionBase : IDisposable, IFunctions
    {
        public string FunctionName { get; set; }
        public Dictionary<string, string> Parameters { get; set; }
       
        
        public HttpContext Context { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionBase" /> class.
        /// </summary>
        public FunctionBase()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionBase" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        public FunctionBase(HttpContext context)
        {
            this.Context = context;
            this.Parameters = new Dictionary<string, string>();
            foreach (string item in context.Request.QueryString.Keys)
            {
                try
                {
                    Parameters.Add(item.ToLower(), context.Request.QueryString[item].Replace(" ", "+"));
                }
                catch (Exception)
                {
                }
            }
            InitializeBaseProperties();
        }

        /// <summary>
        /// Initializes the base properties.
        /// </summary>
        private void InitializeBaseProperties()
        {
            try
            {
             
                try
                {
                    FunctionName = Parameters["function"].ToLower();
                }
                catch
                {
                }
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing,
        /// or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <returns></returns>
        public virtual string Execute()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Initializes the properties.
        /// </summary>
        public virtual void InitializeProperties()
        {
            throw new NotImplementedException();
        }
    }
}